<template>
  <div>
    <!-- 分页查询 -->
    <el-row>
      <el-col :span="4">
        <el-input
          placeholder="档案号/姓名"
          type="text"
          style="width: 100%"
          v-model="name"
        />
      </el-col>
      <el-col :span="2">
        <el-button
          type="primary"
          style="width: 80%; margin-left: 16px"
          icon="el-icon-search"
          @click="page()"
          >搜索</el-button
        >
      </el-col>
      <el-col :span="20"></el-col>
    </el-row>
    <hr />
    <el-table :data="list" border style="width: 100%;height=90%">
      <el-table-column prop="filenumber" label="档案号"> </el-table-column>
      <el-table-column prop="name" label="姓名"> </el-table-column>
      <el-table-column prop="sex" label="性别">
        <template slot-scope="scope">
          {{ scope.row.sex == 1 ? "男" : "女" }}
        </template>
      </el-table-column>

      <el-table-column prop="age" label="年龄"> </el-table-column>
      <el-table-column prop="phonenumber" label="手机号"> </el-table-column>
      <el-table-column prop="email" label="邮箱"> </el-table-column>
      <el-table-column prop="createtime" label="建党时间"> </el-table-column>

      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            size="mini"
            @click="loadAddUP(scope.$index, scope.row)"
            type="primary"
            :plain="scope.row.interposescheme == null ? true : false"
            >{{
              scope.row.interposescheme == null ? "定制方案" : "修改方案"
            }}</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="num"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>
  </div>
</template>

<script>
export default {
  data() {
    return {
      // 分页查询
      num: 1,
      size: 10,
      total: 2,
      list: [],
      name: "",
    };
  },
  methods: {
    // 分页查询
    handleSizeChange(val) {
      this.size = val;
      this.page();
    },
    handleCurrentChange(val) {
      this.num = val;
      this.page();
    },
    page() {
      const loading = this.$loading({
        lock: true,
        text: "正在加载数据中...",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)",
      });
      this.axios
        .get("/rear/Interposescheme/page", {
          params: { num: this.num, size: this.size, name: this.name.trim() },
        })
        .then((res) => {
          console.log(res.data.list);
          this.list = res.data.list;
          this.total = res.data.total;
          loading.close();
        })
        .catch((res) => {
          this.$message.error("服务器出现问题，请联系管理员！");
          loading.close();
        });
    },
    loadAddUP(index,row) {
      sessionStorage.setItem("Member",JSON.stringify(row));
      this.$store.commit("setMember", row);
      this.$router.push(
        "/index/dingzhifangan?menusText=健康干预,干预方案,定制方案"
      );
    },
  },
  created() {
    this.page();
  },
};
</script>

<style scoped>
.d {
  margin: auto;
}
</style>